package com.pvdnc.tapkit.utils;

import android.content.Context;
import android.content.Intent;

public abstract class AppStatusReceiver extends BaseLocalReceiver {
    public static final String ACTION="app.status";

    public AppStatusReceiver() {
        super(ACTION);
    }

    public static void broadcast(int status){
        Intent intent=new Intent();
        intent.setAction(ACTION);
        intent.putExtra(EXTRA_STATUS,status);
        LocalBroadcast.getInstance().send(intent);
    }

    private int getStatus(Intent intent){
        return intent.getIntExtra(EXTRA_STATUS,-1);
    }

    public static final String EXTRA_STATUS="status";

    public static final int STATUS_FOREGROUND=0;

    public static final int STATUS_BACKGROUND=1;

    @Override
    public final void onReceive(Context context, Intent intent) {
        int status=getStatus(intent);
        if(status<0)
            return;
        onReceive(context,status);
    }

    public abstract void onReceive(Context context,int status);
}
